package com.xjy.web.controller.controller;

import java.util.List;
import java.util.Arrays;


import com.xjy.system.service.IReportContractResultService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.ReportContractResultVo;
import com.xjy.system.domain.bo.ReportContractResultQueryBo;
import com.xjy.system.domain.bo.ReportContractResultAddBo;
import com.xjy.system.domain.bo.ReportContractResultEditBo;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
 * VIEWController
 *
 * @author xjy
 * @date 2022-04-03
 */
@Api(value = "合同结算控制器", tags = {"合同结算管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/report_contract_result")
public class ReportContractResultController extends BaseController {

    private final IReportContractResultService iReportContractResultService;

    /**
     * 查询VIEW列表
     */
    @ApiOperation("查询VIEW列表")
    @PreAuthorize("@ss.hasPermi('system:result:list')")
    @GetMapping("/list")
    public TableDataInfo<ReportContractResultVo> list(@Validated ReportContractResultQueryBo bo) {
        return iReportContractResultService.queryPageList(bo);
    }

    /**
     * 导出VIEW列表
     */
    @ApiOperation("导出VIEW列表")
    @PreAuthorize("@ss.hasPermi('system:result:export')")
    @Log(title = "合同结算详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ReportContractResultVo> export(@Validated ReportContractResultQueryBo bo) {
        List<ReportContractResultVo> list = iReportContractResultService.queryList(bo);
        ExcelUtil<ReportContractResultVo> util = new ExcelUtil<ReportContractResultVo>(ReportContractResultVo.class);
        return util.exportExcel(list, "合同结算详情");
    }

    /**
     * 获取VIEW详细信息
     */
    @ApiOperation("获取VIEW详细信息")
    @PreAuthorize("@ss.hasPermi('system:result:query')")
    @GetMapping("/{id}")
    public AjaxResult<ReportContractResultVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iReportContractResultService.queryById(id));
    }

    /**
     * 新增VIEW
     */
    @ApiOperation("新增VIEW")
    @PreAuthorize("@ss.hasPermi('system:result:add')")
    @Log(title = "合同结算详情", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ReportContractResultAddBo bo) {
        return toAjax(iReportContractResultService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改VIEW
     */
    @ApiOperation("修改VIEW")
    @PreAuthorize("@ss.hasPermi('system:result:edit')")
    @Log(title = "合同结算详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ReportContractResultEditBo bo) {
        return toAjax(iReportContractResultService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除VIEW
     */
    @ApiOperation("删除VIEW")
    @PreAuthorize("@ss.hasPermi('system:result:remove')")
    @Log(title = "合同结算详情" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iReportContractResultService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
